﻿// owner 蒋家伟

#pragma once

// qt
#include <QTimer>

// jsdk
#include "ITaskGroup.h"
#include "ITask.h"
#include "TaskId.h"
#include "ITaskDescription.h"

namespace jsdk
{
    class TaskGroup : public ITaskGroup
    {
    public:
        static OwnerPtr<ITaskGroup> create(const std::wstring& description, std::vector<OwnerPtr<ITaskDescription>>&& opTaskDescriptions, uint32_t delayTime);
        virtual ~TaskGroup() {}

    public:
        // 转移所有任务
        std::vector<OwnerPtr<ITask>> transformOwnShip();
    private:
        // 集成ITask
        virtual const ITaskDescription* getTaskDescription() const override;
        virtual const TaskId& getGroupId() const override;
        virtual bool isInGroup() const override;
        virtual const TaskId& getTaskId() const override;
        virtual void setTaskId(const TaskId& taskId) override;
        virtual void setTaskGroupId(const TaskId& taskGroupId) override;
        virtual bool exctue() override;
        virtual bool hasDelayTime() const override;
        virtual void startTimer() const override;
        virtual uint32_t getDelayTime() const override { return m_delayTime; };
        virtual void setDelayTime(uint32_t delayTime) { m_delayTime = delayTime; };

    private:
        TaskGroup(const std::wstring& description, std::vector<OwnerPtr<ITaskDescription>>&& opTaskDescriptions, uint32_t delayTime);
        TaskId m_taskId;
        std::wstring m_description;
        std::vector<OwnerPtr<ITask>> m_tasks;
        QTimer m_timer;
        uint32_t m_delayTime = 0;
    };
}